
$(function(){
	
})

layui.use(['form', 'layedit', 'laydate','table'], function(){
	 var table = layui.table
	  ,laydate = layui.laydate
	  ,form = layui.form
	  ,layer = layui.layer
	  ,layedit = layui.layedit;
	 
	 
	  //监听工具条
	  table.on('tool(demo)', function(obj){
		  //点击审核
		  if(obj.event === 'shenhe'){
			  var index = layer.open({
	    	        type: 1	 //此处以iframe举例
	    	        ,title: '财务审核'
	    	        ,offset: 'auto'
	    	        ,area: ['450px', '300px']
	    	        ,content:$('#add3')
	    	        ,success: function(layero){
	    	        	$("#zuihoutijiao").click(function(){
	    	        		var index2 = layer.load(0, {
	    	        			  shade: [0.5,'#fff'] //0.5透明度的白色背景
	    	        		});
	    	        		if($("#shenheyijian").val()!=''){
	    	      			  var url="../../financeschasesnaudit/financessnaudit.action";
	    	      			  var data={"purId":obj.data.purId,"isva":2,"sort":2,"auState":$("input[name='sex']:checked").val(),"auIdea":$("#shenheyijian").val(),"purSum":obj.data.purSum};
	    	      			  $.post(url,data,function(mes){
	    	      				  if(mes.state==2){
	    	      					 layer.msg('财务资金不足', {icon: 2});
		    	      				layer.close(index);//关闭当前页
	    	      				  }else if(mes.state==1){
	    	      					layer.close(index);//关闭当前页
	    	      					
	    	      					$("#shenheyijian").val("");
	    	      						table.reload('idTest', {
	    	      					        page: {
	    	      					          curr: 1 //重新从第 1 页开始
	    	      					        }
	    	      						})
	    	      					layer.msg('审核成功', {icon: 1});
	    	      				  }else{
	    	      					  layer.msg('审核失败', {icon: 2});
	    	      						table.reload('idTest', {
	    	      					        page: {
	    	      					          curr: 1 //重新从第 1 页开始
	    	      					        }
	    	      						})
	    	      				  }
	    	      			  },"json");
	    	        		}else{
	    	        			$("#shenheyijian").val("");
	    	        			layer.msg('请填写审核意见', {icon: 2});
	    	        		}
	    	        		layer.close(index2);
	    	        	});
	    	        },end : function() {
	    	        	$("#add3").hide();
	    	        	$("#shenheyijian").val("");
	    	        }
	    	    });
		  }else if(obj.event === 'spxq'){
			 
			  layer.open({
	    	        type: 1	 //此处以iframe举例
	    	        ,title: '商品详情'
	    	        ,offset: 'auto'
	    	        ,area: ['1000px', '490px']
	    	        ,content:$('#add')
	    	        ,success: function(layero){
	    	        	//重载表单
	    	        	 table.reload('idTest2', {
	    	     	        page: {
	    	     	          curr: 1 //重新从第 1 页开始
	    	     	        },where: {
	    	     	        	purId: obj.data.purId,
							}
	    	     	      });
	    	        },end : function() {
	    	        	$("#add").hide();
	    	        }
	    	    });
		  }else if(obj.event === 'shxq'){
			  layer.open({
	    	        type: 1	 //此处以iframe举例
	    	        ,title: '商品详情'
	    	        ,offset: 'auto'
	    	        ,area: ['1000px', '490px']
	    	        ,content:$('#add4')
	    	        ,success: function(layero){
	    	        	//重载表单
	    	        	 table.reload('idTest4', {
	    	     	        page: {
	    	     	          curr: 1 //重新从第 1 页开始
	    	     	        },where: {
	    	     	        	purId: obj.data.purId,
							}
	    	     	      });
	    	        },end : function() {
	    	        	$("#add4").hide();
	    	        }
	    	    });
		  }
	  });
	 
	 
	 //日期
	  laydate.render({
	    elem: '#date'
	  });
	  
	  laydate.render({
		    elem: '#time'
	  });
	  
	
	  //采购表条件查询
	  var $ = layui.$, active = {
	    reload: function(){
	      var date = $('#date');
	      var time = $('#time');
	      //执行重载
	      table.reload('idTest', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	        	//把值赋给模型类
	        	optime: date.val(),
	        	opdate: time.val()
	        }
	      });
	    }
	  };
	  //查询
	  $('.demoTable .layui-btn').on('click', function(){
		    var type = $(this).data('type');
		    active[type] ? active[type].call(this) : '';
	  });
})



//表单渲染 
function load() {
	 var form = layui.form
	 form.render();
}